﻿// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This file is part of CodingEditor.
// Note:	This project is derived from Peter Project
//			(hosted on sourceforge and codeplex)
//
// Copyright (c) 2008-2009, CE Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


namespace CE.Main
{
	using System;
    using System.Text.RegularExpressions;
	using System.Windows.Forms;

	using CE.API;

	using WeifenLuo.WinFormsUI.Docking;

	public sealed class DocViewer : DockContent, ICEPluginTab
	{
		#region Fields

		private DockPanel MainDockPanel;
		private ColumnHeader colHeader1;
		private ListBox lstbxDocsView;

		#endregion Fields

		#region Constructors

		public DocViewer(ICEPluginHost host)
		{
			Host = host;
			TabText = "DocViewer";
			InitializeComponent();
		}

		#endregion Constructors

		#region Properties

		public bool AbleToCopy
		{
			get { return false; }
		}

		public bool AbleToCut
		{
			get { return false; }
		}

		public bool AbleToDelete
		{
			get { return false; }
		}

		public bool AbleToPaste
		{
			get { return false; }
		}

		public bool AbleToRedo
		{
			get { return false; }
		}

		public bool AbleToSave
		{
			get { return false; }
		}

		public bool AbleToSelectAll
		{
			get { return false; }
		}

		public bool AbleToUndo
		{
			get { return false; }
		}

		public string FileName
		{
			get { return ""; }
		}

		public ICEPluginHost Host
		{
			get; set;
		}

		public bool NeedsSaving
		{
			get { return false; }
		}

		public string Selection
		{
			get { return ""; }
		}

		#endregion Properties

		#region Methods

		/// <summary>
		/// Adds the specified file to the list.
		/// </summary>
		/// <param name="file">The file.</param>
		public void Add(string file)
		{
			lstbxDocsView.Items.Add(file);
		}

		/// <summary>
		/// Adds all of the opened files
		/// </summary>
		/// <param name="mainDockPanel">The main dock panel.</param>
		public void Add(DockPanel mainDockPanel)
		{
			MainDockPanel = mainDockPanel;

			if (lstbxDocsView.Items.Count < 1) {
				foreach (DockContent content in MainDockPanel.Contents) {
					if (content.GetType() != typeof (SourceEditor)) continue;

					if (content.TabText != null)
						lstbxDocsView.Items.Add(content.TabText);
				}
			}
		}

		/// <summary>
		/// Closes the tab.
		/// </summary>
		/// <returns></returns>
		public bool CloseTab()
		{
			return false;
		}

		public void Copy()
		{
		}

		public void Cut()
		{
		}

		public void Delete()
		{
		}

		public void Duplicate()
		{
		}

		/// <summary>
		/// Finds the next.
		/// </summary>
		/// <param name="reg">The reg.</param>
		/// <param name="searchUp">if set to <c>true</c> [search up].</param>
		/// <returns></returns>
		public bool FindNext(Regex reg, bool searchUp)
		{
			return false;
		}

		public void ItemActivation( DockPanel dock)
		{
			for (int i = 0; i < dock.Contents.Count; i++) {
				if (dock.Contents[i].GetType() != typeof (SourceEditor)) continue;
				var tab = (ICEPluginTab) dock.Contents[i];
				if (tab.TabText == (string)lstbxDocsView.SelectedItem)
					dock.Contents[i].DockHandler.Activate();
			}
		}

		public void MarkAll( Regex reg)
		{
		}

		public void Paste()
		{
		}

		public void Print(bool showDialog)
		{
		}

		public void Redo()
		{
		}

		public void ReplaceAll( Regex reg,  string replaceWith)
		{
		}

		public void ReplaceNext( Regex reg,  string replaceWith, bool searchUp)
		{
		}

		public void Save()
		{
		}

		public void SaveAs( string filePath)
		{
		}

		public void SelectAll()
		{
		}

		public void SelectWord(int line, int offset, int wordLeng)
		{
		}

		public void Undo()
		{
		}

		private void DocumentSelector_FormClosed(object sender, FormClosedEventArgs e)
		{
			Dispose(true);
		}

		private void InitializeComponent()
		{
			this.colHeader1 = new System.Windows.Forms.ColumnHeader();
			this.lstbxDocsView = new System.Windows.Forms.ListBox();
			this.SuspendLayout();
			//
			// colHeader1
			//
			this.colHeader1.Text = "";
			this.colHeader1.Width = 190;
			//
			// lstbxDocsView
			//
			this.lstbxDocsView.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.lstbxDocsView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.lstbxDocsView.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.lstbxDocsView.FormattingEnabled = true;
			this.lstbxDocsView.ItemHeight = 16;
			this.lstbxDocsView.Location = new System.Drawing.Point(0, 0);
			this.lstbxDocsView.Name = "lstbxDocsView";
			this.lstbxDocsView.Size = new System.Drawing.Size(140, 98);
			this.lstbxDocsView.TabIndex = 1;
			this.lstbxDocsView.SelectedIndexChanged += new System.EventHandler(this.lstbxDocsView_ItemActivate);
			//
			// DocViewer
			//
			this.ClientSize = new System.Drawing.Size(140, 98);
			this.Controls.Add(this.lstbxDocsView);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
			this.Name = "DocViewer";
			this.ResumeLayout(false);
		}

		private void lstbxDocsView_ItemActivate(object sender, EventArgs e)
		{
			ItemActivation( MainDockPanel);
		}

		#endregion Methods
	}
}